import Vue from 'vue'
import App from './app.vue'
import router from './routes.js'
import store from './store.js'
// import Common from '../static/dominate/js/vueCommon'
import * as filters from './filter/index'
import { getCookie } from './assets/js/common'

import {
    Button,
    Dialog,
    Pagination,
    Input,
    Radio,
    RadioGroup,
    DatePicker,
    Popover,
    Collapse,
    CollapseItem,
    Switch,
    Form,
    FormItem,
    Message,
    Select,
    Option,
    Cascader,
    MessageBox,
    Table,
    TableColumn,
    Menu,
    Submenu,
    MenuItem,
    MenuItemGroup,
    Tabs,
    TabPane,
    Tooltip,
    Breadcrumb,
    BreadcrumbItem,
    Checkbox,
    InputNumber,
    Upload,
    Loading,
    Row,
    Col
} from 'element-ui'

Vue.use(Button)
Vue.use(DatePicker)
Vue.use(Collapse)
Vue.use(CollapseItem)
Vue.use(Menu)
Vue.use(Submenu)
Vue.use(MenuItem)
Vue.use(MenuItemGroup)
Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Pagination)
Vue.use(Tabs)
Vue.use(TabPane)
Vue.use(Switch)
Vue.use(Tooltip)
Vue.use(Popover)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Select)
Vue.use(Option)
Vue.use(Cascader)
Vue.use(Dialog)
Vue.use(Breadcrumb)
Vue.use(BreadcrumbItem)
Vue.use(Checkbox)
Vue.use(InputNumber)
Vue.use(Upload)
Vue.use(Row)
Vue.use(Col)
Vue.use(Loading.directive)
// Vue.use(Common)

Vue.prototype.$loading = Loading.service
Vue.prototype.$prompt = MessageBox.prompt
Vue.prototype.$message = Message
Vue.prototype.$confirm = MessageBox.confirm

Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})

new Vue({
    el: '#app',
    router,
    store,
    render: (h) => h(App),
    created: function () {
        let role = getCookie('adminRole') ? Number(getCookie('adminRole')) : 1
        let routes
        if (role === 0) {
            routes = [
                {
                    path: '/',
                    name: 'index',
                    component: () => import(/* webpackChunkName: "index" */ './pages/index.vue'),
                    children: [
                        {
                            path: '/userList/:page',
                            name: 'userList',
                            meta: { title: '管理员管理' },
                            props: true,
                            component: () => import(/* webpackChunkName: "userList" */ './pages/userList.vue')
                        },
                        {
                            path: '/movieList/:page',
                            name: 'movieList',
                            meta: { title: '视频管理' },
                            props: true,
                            component: () => import(/* webpackChunkName: "movieList" */ './pages/movieList.vue')
                        },
                        {
                            path: '*',
                            name: '404',
                            component: () => import(/* webpackChunkName: "404" */ './pages/404.vue')
                        }
                    ]
                }
            ]
        } else if (role === 1) {
            routes = [
                {
                    path: '/',
                    name: 'index',
                    component: () => import(/* webpackChunkName: "index" */ './pages/index.vue'),
                    children: [
                        {
                            path: '/userList/:page',
                            name: 'userList',
                            meta: { title: '管理员管理' },
                            props: true,
                            component: () => import(/* webpackChunkName: "userList" */ './pages/userList.vue')
                        },
                        {
                            path: '*',
                            name: '404',
                            component: () => import(/* webpackChunkName: "404" */ './pages/404.vue')
                        }
                    ]
                }
            ]
        }
        this.$router.addRoutes(routes)
    }
})
